(function (vc, vm) {

    vc.extends({
        data: {
            buyShopSmsInfo: {
                smsPrice: '',
                buyCount: '',
                amount: '0',
                qrCode: '',
                remark: '',
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('buyShopSms', 'openBuyShopSmsModal', function (_params) {
                $that.refreshBuyShopSmsInfo();
                $('#buyShopSmsModel').modal('show');
                vc.copyObject(_params, $that.buyShopSmsInfo);
                $that.buyShopSmsInfo.shopId = vc.getCurrentCommunity().shopId;
            });
        },
        methods: {
            buyShopSmsValidate: function () {
                return vc.validate.validate({
                    buyShopSmsInfo: $that.buyShopSmsInfo
                }, {
                    'buyShopSmsInfo.shopId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "店铺ID不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "店铺ID不能超过30"
                        },
                    ],
                    'buyShopSmsInfo.buyCount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "购买数量不能为空"
                        }
                    ],
                });
            },
            _computeSmsAmount: function () {
                if (!$that.buyShopSmsValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    '/shopSms.computeSmsAmount',
                    JSON.stringify($that.buyShopSmsInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        let _json = JSON.parse(json);
                        if (_json.code != 0) {
                            //关闭model
                            vc.toast(_json.msg);
                            return;
                        }
                        vc.copyObject(_json.data,$that.buyShopSmsInfo);
                        setTimeout(function(){
                            $that._viewBuySmsQr();
                        },1000);
                        
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.toast(errInfo);
                    });
            },
            refreshBuyShopSmsInfo: function () {
                $that.buyShopSmsInfo = {
                    smsPrice: '',
                    buyCount: '',
                    amount: '0',
                    qrCode: '',
                    remark: '',

                }
            },
            _viewBuySmsQr: function() {
                document.getElementById("buySmsQrCodeDiv").innerHTML = "";
                let qrcode = new QRCode(document.getElementById("buySmsQrCodeDiv"), {
                    text: "213", //你想要填写的文本
                    width: 200, //生成的二维码的宽度
                    height: 200, //生成的二维码的高度
                    colorDark: "#000000", // 生成的二维码的深色部分
                    colorLight: "#ffffff", //生成二维码的浅色部分
                    correctLevel: QRCode.CorrectLevel.L
                });
                qrcode.makeCode($that.buyShopSmsInfo.qrCode);
            },
            _finishBuySms:function(){
                $('#buyShopSmsModel').modal('hide');
                vc.emit('shopConfigSms','listShopSms',{});
            }
        }
    });

})(window.vc, window.$that);
